#include <bits/stdc++.h>
using namespace std;
int m,n,l,v,t,s=0;
int aa[1000005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int a,b,c;
    cin>>t;
    while (t--){
         cin>>n>>m>>l>>v;
         for (int i=1;i<=n;i++){
            cin>>a>>b>>c;
            if (b>v)s++;
        }
        for (int j=1;j<=m;j++){
        cin>>aa[j];
        }
        cout<<s<<m-2;
    }
    return 0;
}
